//
//  AMIntegralCountView.m
//  DemoForSignIn
//
//  Created by  高东星 on 17/8/28.
//  Copyright © 2017年 anmur. All rights reserved.
//

#import "AMIntegralCountView.h"


@interface AMIntegralCountView ()


@property (nonatomic,weak) UIImageView *backgroundImageView;
@property (nonatomic,weak) UILabel *contentLabel;

@end





@implementation AMIntegralCountView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self addBackgroundImageView];
        [self addContentLalbel];
    }
    return self;
}




- (void)setState:(AMIntegralCountViewState)state{
    switch (state) {
        case AMIntegralCountViewStateNormal:
            self.contentLabel.textColor = [UIColor whiteColor];
            break;
        case AMIntegralCountViewStateHlighted:
            self.contentLabel.textColor = [UIColor redColor];
            break;
        default:
            break;
    }
}




- (void)addBackgroundImageView{
    UIImageView *backgroundImageView = [UIImageView new];
    backgroundImageView.contentMode = UIViewContentModeScaleToFill;
    backgroundImageView.image = [UIImage imageNamed:@"integral_background"];
    [self addSubview:backgroundImageView];
    _backgroundImageView = backgroundImageView;
}

- (void)addContentLalbel{
    UILabel *contentLabel = [UILabel new];
    contentLabel.font = [UIFont systemFontOfSize:10];
    contentLabel.textAlignment = NSTextAlignmentCenter;
    contentLabel.numberOfLines = 2;
    [self addSubview:contentLabel];
    _contentLabel = contentLabel;
}


- (void)layoutSubviews{
    [super layoutSubviews];
    
    _backgroundImageView.frame = self.bounds;
    _contentLabel.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 3);
}

- (void)setIntegralCount:(NSInteger)integralCount{
    _integralCount = integralCount;
    self.contentLabel.text = [NSString stringWithFormat:@"+%zd\r\n积分",integralCount];
}

@end
